package com.teadent.servlet;

import com.teadent.bean.Person;
import com.teadent.service.UserLoginService;
import com.teadent.service.UserLoginServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/userLogin")
public class UserLoginServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        String userAccount = req.getParameter("userAccount");
        String userPassword =req.getParameter("userPassword");
        Person person=new Person(userAccount,userPassword);
        UserLoginService ul=new UserLoginServiceImpl();
        Person newPerson=ul.getLogin(person);
        if(newPerson!=null){
            //前往功能主页
            HttpSession session= req.getSession();
            req.getSession().setAttribute("session_person",newPerson);
            req.setAttribute("mainRight","blank.jsp");
            req.getRequestDispatcher("main.jsp").forward(req,resp);
        } else {
            //返回登录界面
            req.setAttribute("tip","账号密码输入错误");
            req.getRequestDispatcher("userLogin.jsp").forward(req,resp);

        }



    }
}
